import VeeValidate, { Validator } from 'vee-validate'

// 进行验证信息的自定义
const dict = {
  custom: {
    name: {
      required: '名称不能为空',
      max: '名称长度过长'
    },
    account: {
      required: '用户名不能为空',
      max: '用户名长度过长'
    },
    password: {
      required: '密码不能为空',
      min: '密码长度不少于6位',
      max: '密码长度不超过64位'
    },
    repassword: {
      required: '确认密码不能为空',
    },
    password1: {
      required: '两次密码必须一致',
    },
    accounts: {
      required: '账号不能为空'
    },

    phone: {
      required: '手机号不能为空'
    },
    verification: {
      required: '验证码不能为空'
    },
    
    parmeter_type: {
      required: '参数类型不能为空'
    },
    pwe:{
      required: '参数值不能为空'
    },
    days: {
      required: '有效期不能为空'
    },
    newpassword:{
      required: '新密码不能为空',
      confirmed: '两次密码不一致'
    },
    new_password:{
      required: '新密码不能为空',
    },
    renew_password:{
      required: '确定密码不能为空',
      confirmed: '两次密码不一致'
    },
    resetPassword:{
      required: '新密码不能为空',
    },
    sumbitRepassword:{
      required: '确认密码不能为空',
    },
    oldPassword: {
      required: '旧密码不能为空',
    },
 
    floor: {
      required: '楼层不能为空'
    },
    branch: {
      required: '车间不能为空'
    },
    line: {
      required: '条线不能为空'
    },
    seq: {
      required: '序号不能为空'
    },
    aliasName: {
      required: '设备名称不能为空'
    },
    cnc_name: {
      required: 'CNC类型不能为空'
    },
    port: {
      required: '端口号不能为空'
    },
    serial: {
      required: '设备识别号不能为空'
    },

    groupName: {
      required: '分组名称不能为空'
    },

    field_type: {
      required: '类型不能为空'
    },

    addr: {
      required: '参数地址不能为空'
    },

    data_type: {
      required: '数据类别不能为空'
    },
    
    username: {
      required: '用户名不能为空'
    },
    role: {
      required: '角色不能为空'
    }, 
    purpose: {
      required: '用途不能为空'
    },

    templateName: {
      required: '模板名称不能为空'
    },

    freq: {
      required: '上报频率不能为空'
    },

    http_url: {
      required: '服务器URL不能为空'
    },
    mqtt_ip: {
      required: '服务器地址不能为空'
    },
    mqtt_port: {
      required: '端口号不能为空'
    },
    mqtt_username: {
      required: '用户名不能为空'
    },
    mqtt_password: {
      required: '密码不能为空'
    },
    mqtt_topic: {
      required: 'Topic名称不能为空'
    },
    
    paramsName: {
      required: '参数名称不能为空'
    },

    field: {
      required: 'ID不能为空'
    },

    programUrl: {
      required: '版本文件不能为空'
    },

    version: {
      required: '版本号不能为空'
    },

    fileName: {
      required: '参数名称不能为空'
    },
    fileIcon: {
      required: '封面不能为空'
    },
    serviceName: {
      required: '服务名称不能为空'
    },
    refreq: {
      required: '上报频率不能为空'
    },
    method: {
      required: '上报方式不能为空'
    },
    serviceUrl: {
      required: 'URL不能为空'
    },


    pointName: {
      required: '点位名称不能为空'
    },
    source: {
      required: '数据来源不能为空'
    },
    calculate_type: {
      required: '计算类型不能为空'
    },
    formula: {
      required: '计算公式不能为空'
    },

    tempId: {
      required: '关联模板不能为空'
    },
  }
}

// 长度为4位数的 maxLength
Validator.extend('maxLength4', {
  getMessage: field => '最大字符长度为4',
  validate: value => value.length <= 4
})
// 长度为4位数的 maxLength
Validator.extend('maxLength5', {
  getMessage: field => '最大长度为5',
  validate: value => value.length <= 5
})
// 长度为10位数的 maxLength
Validator.extend('maxLength10', {
  getMessage: field => '最大长度为10',
  validate: value => value.length <= 10
})
// 长度为16位数的 maxLength
Validator.extend('maxLength16', {
  getMessage: field => '最大长度为16',
  validate: value => value.length <= 16
})
Validator.extend('maxLength8', {
  getMessage: field => '最大字符长度为8',
  validate: value => value.length <= 8
})
// 长度为30位数的 maxLength
Validator.extend('maxLength30', {
  getMessage: field => '最大字符长度为30',
  validate: value => value.length <= 30
})
// 长度为50位数的 maxLength
Validator.extend('maxLength50', {
  getMessage: field => '最大字符长度为50',
  validate: value => value.length <= 50
})
// 长度为100位数的 maxLength
Validator.extend('maxLength100', {
  getMessage: field => '最大字符长度为100',
  validate: value => value.length <= 100
})
// 长度为120位数的 maxLength
Validator.extend('maxLength120', {
  getMessage: field => '最大字符长度为120',
  validate: value => value.length <= 120
})
// 长度为128位数的 maxLength
Validator.extend('maxLength128', {
  getMessage: field => '最大长度为128',
  validate: value => value.length <= 128
})
// 长度为300位数的 maxLength
Validator.extend('maxLength300', {
  getMessage: field => '最大字符长度为300',
  validate: value => value.length <= 300
})
// 只允许正整数和0
Validator.extend('onlyRule0', {
  getMessage: field => '只允许正整数和0',
  validate: value => /^[0-9]+$/.test(value)
})
// 只允许数字、小数点和-
Validator.extend('onlyRule1', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.-]+$/.test(value)
})
// 只允许数字、小数点
Validator.extend('onlyRule2', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule3', {
  getMessage: field => '只允许数字、英文字母".-:_"字符',
  validate: value => /^[a-zA-Z0-9\.:_-]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule4', {
  getMessage: field => '只允许数字、英文字母".-%_"字符',
  validate: value => /^[a-zA-Z0-9\.:_%-]+$/.test(value)
})
// 只允许正整数
Validator.extend('onlyRule5', {
  getMessage: field => '必须为正整数',
  validate: value => /^[1-9]\d*$/.test(value)
})
// 值小于60
Validator.extend('onlyRule6', {
  getMessage: field => '不能大于60',
  validate: value => parseFloat(value) <= 60
})
// 只允许数字、 英文字母、小 数点 和"-_"字 符'
Validator.extend('onlyRule7', {
  getMessage: field => '只允许中文数字、英文字母"-"字符',
  validate: value => /^[a-zA-Z0-9\u4e00-\u9fa5\-]+$/.test(value)
})
// 只允许数字 0 - 120
Validator.extend('onlyRule8', {
  getMessage: field => '只允许0至120之间数字',
  validate: value => /^(?:[0-9][0-9]?|1[01][0-9]|120)$/.test(value)
})

Validator.extend('phone', {
  getMessage: field => '请输入正确的手机号',
  validate: value => value.length === 11 && /^1[3-9]\d{9}$/.test(value)
})

Validator.extend('email', {
  getMessage: field => '请输入正确的邮箱',
  validate: value => value.length < 32 &&  /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(value)
})

Validator.extend('username', {
  getMessage: field => '请输入16位以内英文加数字组合',
  validate: value => value.length < 16 &&  /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,16}$/.test(value) 
})

Validator.extend('serverUrl', {
  getMessage: field => '请输入正确的服务器地址',
  validate: value => /(((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)(\.((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)){3})|([a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?)/.test(value) 
  // validate: value => /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/.test(value) 
  // validate: value => /^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*([\?&]\w+=\w*)*$/.test(value) 
})

Validator.extend('specialCharacter', {
  getMessage: field => '存在特殊字符(只能是中文、英文或数字)',
  validate: value => /^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(value)
})

Validator.extend('size', {
  getMessage: field => '只能输入大于0的整数',
  validate: value => /^\+?[1-9][0-9]*$/.test(value)
})



Validator.extend('noChinese', {
  getMessage: field => '只能是数字和英文',
  validate: value => /^[A-Za-z0-9]+$/.test(value)
})

Validator.extend('nameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})

Validator.extend('fireNameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 10
})

Validator.extend('remarkLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})


Validator.extend('contract_number', {
  getMessage: field => '合同编码不能超过32位',
  validate: value => value.length <= 32
})
Validator.extend('onnumber', {
  getMessage: field => '只允许数字',
  validate: value => /^[0-9]+$/.test(value)
})
Validator.extend('password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})
Validator.extend('newpassword', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})

Validator.extend('old-password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})



Validator.extend('new-password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})
Validator.extend('name', {
  getMessage: field => '请输入不能超过64汉字',
  validate: value => value.length <= 64  && /^[\u4E00-\u9FA5]{1,64}$/.test(value) 
})

Validator.extend('companyName', {
  getMessage: field => '机构名称只能输入中文并且不能超过64位',
  validate: value =>  /^[\u4E00-\u9FA5]{1,64}$/.test(value) 
})

Validator.extend('roleName', {
  getMessage: field => '只能输入16位以内的中文',
  validate: value => /^[\u4E00-\u9FA5]{1,16}$/.test(value)
})

// &&  /^[\u4E00-\u9FA5]{6,64}$/.test(value) 
Validator.extend('location', {
  getMessage: field => '详细地址不能超过64位',
  validate: value => value.length <= 64  
})
Validator.extend('serial', {
  getMessage: field => '主控序列号不能超过128位',
  validate: value => value.length <= 128  
})



Validator.extend('maxLength32', {
  getMessage: field => '长度不能超过32位',
  validate: value => value.length <= 32
})


Validator.extend('html', {
  getMessage: field => '内嵌html格式不正确',
  validate: value =>/^https?:\/\/(.*)/ .test(value)
})
// Validator.extend('maxLength16', {
//   getMessage: field => '长度不能超过16位',
//   validate: value => value.length <= 16
// })

Validator.extend('suffix', {
  getMessage: field => '只能输入输入英文、数字、英文状态下的逗号',
  validate: value =>  /^[a-zA-Z0-9\,]+$/.test(value)
})


Validator.extend('nickName', {
  getMessage: field => '昵称只能输入8位以内的中文',
  validate: value => /^[\u4E00-\u9FA5]{1,8}$/.test(value)
})
export const Config = {
  fieldsBagName: 'veefields'
}
Validator.localize('en', dict)
export default VeeValidate
